const getters = {
  device: state => state.app.device,
  formOpenType: state => state.app.formOpenType,
  theme: state => state.app.theme,
  portal: state => state.app.portal,
  color: state => state.app.color,
  token: state => state.user.token,
  avatar: state => state.user.info.avatar,
  username: state => state.user.info.username,
  nickname: state => state.user.info.realname,
  orgname: state => state.user.info.orgName,
  permissionList: state => state.user.permissionList,
  switchDepartments: state => state.user.switchDepartments,
  userInfo: state => state.user.info,
  addRouters: state => state.permission.addRouters,
  back: state => state.user.info.backRoleFlg === "1",
  locale: state => state.locale.data,
  language: state => state.locale.language,
  customTableColumns: state => key => {
    return state.custom.customTableColumns[key];
  },
  CONSOLE_INDEX_MAIN_PAGE_PATH: state => state.user.CONSOLE_INDEX_MAIN_PAGE_PATH,
  CONSOLE_INDEX_MAIN_PAGE_NAME: state => state.user.CONSOLE_INDEX_MAIN_PAGE_NAME,
  activatedFirst: state=>state.permission.activatedFirst,
  firstMenu(state, getters) {
    const menuData = getters.permissionList.filter(vo => vo.back == "0")
    return menuData.map(item => {
      const menuItem = {...item}
      delete menuItem.children
      return menuItem
    })
  },
  subMenu(state, getters) {
    const activatedFirst = state.permission.activatedFirst
    const menuData = getters.permissionList.filter(vo => vo.back == "0")
    const current = menuData.find(menu => menu.path === activatedFirst)
    return current && current.children || []
  }
}

export default getters
